package org.cbg.control;

import java.math.BigDecimal;
import java.util.List;

import org.cbg.bean.SearchGoodsResultBean;
import org.cbg.entity.Salegoods;
import org.cbg.frame.TrslationMainJframe;
import org.cbg.panel.TraslationWantBuyCardJapel;
import org.cbg.until.TraslationTableDahuabiUntil;
import org.cbg.until.TraslationTableUntil;
import org.come.action.FromServerAction;
import org.come.until.GsonUtil;

/**
 * 藏宝阁物品搜索类回调
 * 
 * @author Administrator
 * 
 */
public class SearchGoodsResultControl implements FromServerAction {

    @Override
    public void controlMessFromServer(String mes, String type) {

        // 消息处理部分转换为SearchGoodsResultBean对象
        SearchGoodsResultBean sa = GsonUtil.getGsonUtil().getgson().fromJson(mes, SearchGoodsResultBean.class);

        /**
         * 确认打开那个窗口(1、首页 2、大话币 3、道具 4、召唤兽 5、装备 6、灵宝 7、公示期 8、收藏 9、我要卖之已寄售品 )
         */
        /**
         * 保存收藏物品集合
         */
        if (sa.getCollections() != null) {
            TrslationMainJframe.getTrslationMainJframe().setShoucangWupinList(sa.getCollections());
        }
        TraslationWantBuyCardJapel traslationWantBuyCardJapel = TrslationMainJframe.getTrslationMainJframe().getTrslationMainJpanel().getTranslationMainCardJpanel().getTraslationWantBuyJpanel().getTraslationWantBuyCardJapel();
        switch (TrslationMainJframe.getTrslationMainJframe().getPanelOpen()) {
        case 0:
            List<Salegoods> salegoodsList = sa.getSalegoods();
            List<BigDecimal> bigDecimalsList = sa.getCollections();
            traslationWantBuyCardJapel.getTraslationWantBuyShouyeCardJpanel().getTraslationWantBuyShouyeJpanel().getTraslationWantBuyShouyeModelJpanel()
                    .setZuixinshangjia(salegoodsList);
            /**
             * 展示大话币面板
             */
            traslationWantBuyCardJapel.getCardLayout()
                    .show(traslationWantBuyCardJapel, "shouye");

            break;
        case 1:
            /**
             * 当搜索首页时搜索的结果处理
             */
            // 处理消息添加到界面（传三个参数，JScrollPane ， 商品集合， 收藏商品Id集合）
            TraslationTableUntil.setTableModel(traslationWantBuyCardJapel.getTraslationWantBuyShouyeCardJpanel()
                    .getTraslationWantBuyShouyeSousuojieguoJpanel().getjScrollPane(), sa.getSalegoods(),
                    sa.getCollections());
            // 最大页数
            traslationWantBuyCardJapel.getTraslationWantBuyShouyeCardJpanel()
                    .getTraslationWantBuyShouyeSousuojieguoJpanel().setPage(sa.getTotal() == 0 ? 1 : sa.getTotal());
            // 跳转到搜索结果界面
            traslationWantBuyCardJapel.getTraslationWantBuyShouyeCardJpanel().getCardLayout()
                    .show(traslationWantBuyCardJapel.getTraslationWantBuyShouyeCardJpanel(), "sousuojieguo");
            break;
        case 2:
            /**
             * 当搜索大话币时搜索的结果处理
             */
            // 处理消息添加到界面
            TraslationTableDahuabiUntil.setTableModel(traslationWantBuyCardJapel
                    .getTraslationWantBuyDahuabiJpanel().getjScrollPane(), sa.getSalegoods(), sa.getCollections());
            // 最大页数
            traslationWantBuyCardJapel.getTraslationWantBuyDahuabiJpanel().setPage(
                    sa.getTotal() == 0 ? 1 : sa.getTotal());

            /**
             * 展示大话币面板
             */
            traslationWantBuyCardJapel.getCardLayout()
                    .show(traslationWantBuyCardJapel, "dahuabi");

            break;
        case 3:
            /**
             * 当搜索道具时搜索的结果处理
             */
            // 处理消息添加到界面
            TraslationTableUntil.setTableModel(traslationWantBuyCardJapel.getTraslationWantBuyDaojuJpanel()
                    .getjScrollPane(), sa.getSalegoods(), sa.getCollections());
            // 最大页数
            traslationWantBuyCardJapel.getTraslationWantBuyDaojuJpanel().setPage(
                    sa.getTotal() == 0 ? 1 : sa.getTotal());
            /**
             * 跳转道具页面
             */
            traslationWantBuyCardJapel.getCardLayout()
                    .show(traslationWantBuyCardJapel, "daoju");

            break;
        case 4:
            /**
             * 当搜索召唤兽时搜索的结果处理
             */
            // 处理消息添加到界面
            TraslationTableUntil.setTableModel(traslationWantBuyCardJapel
                    .getTraslationWantBuyZhaohuanshouJpanel().getjScrollPane(), sa.getSalegoods(), sa.getCollections());
            // 最大页数
            traslationWantBuyCardJapel.getTraslationWantBuyZhaohuanshouJpanel().setPage(
                    sa.getTotal() == 0 ? 1 : sa.getTotal());

            /**
             * 展示召唤兽面板
             */
            traslationWantBuyCardJapel.getCardLayout()
                    .show(traslationWantBuyCardJapel, "zhaohuanshou");
            break;
        case 5:
            /**
             * 当搜索装备时搜索的结果处理
             */
            // 处理消息添加到界面
            TraslationTableUntil.setTableModel(traslationWantBuyCardJapel.getTraslationWantBuyZhaungbeiJpanel()
                    .getjScrollPane(), sa.getSalegoods(), sa.getCollections());
            // 最大页数
            traslationWantBuyCardJapel.getTraslationWantBuyZhaungbeiJpanel().setPage(
                    sa.getTotal() == 0 ? 1 : sa.getTotal());
            /**
             * 展示装备面板
             */
            traslationWantBuyCardJapel.getCardLayout()
                    .show(traslationWantBuyCardJapel, "zhuangbei");
            break;
        case 6:
            /**
             * 当搜索灵宝时搜索的结果处理
             */
            // 处理消息添加到界面
            TraslationTableUntil.setTableModel(traslationWantBuyCardJapel.getTraslationWantBuyLingbaoJpanel()
                    .getjScrollPane(), sa.getSalegoods(), sa.getCollections());
            // 最大页数
            traslationWantBuyCardJapel.getTraslationWantBuyLingbaoJpanel().setPage(
                    sa.getTotal() == 0 ? 1 : sa.getTotal());

            /**
             * 展示灵宝面板
             */
            traslationWantBuyCardJapel.getCardLayout()
                    .show(traslationWantBuyCardJapel, "lingbao");
            break;
        case 7:
            /**
             * 当搜索公示期时搜索的结果处理
             */
            // 处理消息添加到界面
            TraslationTableUntil.setTableModel(traslationWantBuyCardJapel.getTraslationWantBuyGongshiqiJpanel()
                    .getjScrollPane(), sa.getSalegoods(), sa.getCollections());

            // 最大页数
            traslationWantBuyCardJapel.getTraslationWantBuyGongshiqiJpanel().setPage(
                    sa.getTotal() == 0 ? 1 : sa.getTotal());

            /**
             * 展示公示期面板
             */
            traslationWantBuyCardJapel.getCardLayout()
                    .show(traslationWantBuyCardJapel, "gongshiqi");
            break;
        case 8:

            break;
        // case 9:
        // /**
        // * 当点击我要卖之已寄售品时的结果处理
        // */
        // /**
        // * 添加数据
        // */
        // TraslationTableYijishangpinUntil.setTableModel(
        // TraslationWantSentYijishangpinJpanel
        // .getTraslationWantSentYijishangpinJpanel()
        // .getjScrollPane(), sa.getSalegoods());
        // /**
        // * 设置最大页数
        // */
        // TraslationWantSentYijishangpinJpanel
        // .getTraslationWantSentYijishangpinJpanel().setPage(
        // sa.getTotal());
        //
        // /**
        // * 展示页面
        // */
        // TraslationWantSendCardJpanel
        // .getTraslationWantSendCardJpanel()
        // .getVcarCardLayout()
        // .show(TraslationWantSendCardJpanel
        // .getTraslationWantSendCardJpanel(),
        // "yijishoupin");
        //
        // break;
        default:
            break;
        }

    }

}
